package user.controller;

import core.constants.HttpConstants;
import core.controller.BaseController;
import core.domain.ListDataInfo;
import core.domain.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import user.aspect.CheckUserStatus;
import user.domain.exam.dto.ExamDTO;
import user.domain.exam.dto.ExamQueryDTO;
import user.service.IUserExamService;

@RestController
@Slf4j
@RequestMapping("/user/exam")
public class UserExamController extends BaseController {
    @Autowired
    private IUserExamService userExamService;

    @PostMapping("/enter") // 竞赛报名
    @CheckUserStatus
    public Result<Void> enter(@RequestHeader(HttpConstants.AUTHENTICATION) String token,
                        @RequestBody ExamDTO examDTO){
        log.info("[UserExamController] -> enter:  {}, {}", examDTO, token);
        int enter = userExamService.enter(token, examDTO.getExamId());
        return toResult(enter);
    }

    @GetMapping("/myList")  // 我的竞赛列表
    public ListDataInfo redisMyList(ExamQueryDTO query) {
        log.info("C -> ExamController -> redisMyList: {}", query);
        return userExamService.redisMyList(query);
    }

}
